var jq = jQuery.noConflict();
	jq(document).ready(function(){			
		jq("form").submit(function(){				
			var errorCount = 0;
			var form_id = jq(this).attr('id');
			jq('form#'+form_id+' input, form#'+form_id+' select,form#'+form_id+' textarea').each(function(){
				if(jq(this).attr('rel')){
					var element_split = jq(this).attr('rel').split(",");
					var size_length = element_split.length;				
					for(var i=0; i<size_length;i++)
					{					
						if(element_split[i]=='required')
						{
							var value = jq(this).val();
							if(value == "" || value == null)
							{
								var title = jq(this).attr("title");
								jq(this).next('.error-validate').html(title+' is required');
								errorCount++;
							}
						}					
						if(element_split[i]=='email')
						{
							var email_check = jq(this).val();
							var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
							if(!emailReg.test( email_check ) )
							{
								jq(this).next('.error-validate').html('Invalid email format');
								errorCount++;
							}
						}
						if(element_split[i]=='phone' && jq(this).val()!='')
						{
							var regex = /(\d.*){10}/;
							if(!jq(this).val().match(regex))
							{
								jq(this).next('.error-validate').html('Not a valid phone number.');
								errorCount++;
							}

							var regex1 = /([^\d]+)/g;
							var phnVal = jq(this).val().replace(regex1,'');
							var number = /(\d)\1{9}/;
							if(phnVal.match(number))
							{
								jq(this).next('.error-validate').html('Not a valid phone number.');
								errorCount++;
							}
						}
						if(element_split[i]=='min_length' && jq(this).val()!='')
						   {  
							var len = jq(this).val().length;
							if(len<6)
							{
								jq(this).next('.error-validate').html('Password length must be of 6 characters');
								errorCount++;  
							}
						}
						var value=element_split[i].split("(");					
						if(value[1]!=undefined || value[1]!=null)
						{
							var check = value[0];
							var par = value[1].split(")");
							var checker = par[0];
							if(element_split[i]=='match('+checker+')')
							{							
								var check_value = jq(this).val();
								var label = jq(this).attr("title");
								var condition_label = jq("#"+checker).attr("title");
								var conf_value_check = jq("#"+checker).val();						
								if(check_value!=conf_value_check )
								{
									jq(this).next('.error-validate').html('Password does not match');
									errorCount++;
								}
							}

						}
					}
				}
			});
			if(errorCount>0)
			{	
				jq(".error-validate").css("display", "block");
				return false;
			}
		});
		jq('form input, select, textarea').blur(function(){
			jq(this).nextAll('.error-validate').html('');
    });    
});

